package com.ihr360.payroll.controller.salary.jobexecution;

import com.ihr360.job.core.entity.JobExecution;
import com.ihr360.job.core.repository.PageData;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.service.salary.jobexecution.BatchJobExecutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author tomtao
 */
@RestController
@RequestMapping("/batch/status")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE_ADMIN,
        mainModuleName = ModuleCodeStore.Module.SALARY_NAME_ADMIN,
        subModuleCode = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_CODE,
        subModuleName = ModuleCodeStore.Module.SalaryAdmin.BATCH_JOB_EXECUTION_NAME)
public class BatchJobExecutionController {

    @Autowired
    private BatchJobExecutionService batchJobExecutionService;

    @FunctionDefinition(functionName = "获取所有任务", functionCode = ModuleCodeStore.Function.VIEW)
    @GetMapping(value = "/all")
    public PageData<JobExecution> all(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "100") int size) {
        return batchJobExecutionService.getJobExecution(page, size);
    }

    @FunctionDefinition(functionName = "获取失败任务", functionCode = ModuleCodeStore.Function.VIEW)
    @GetMapping(value = "/failed")
    public PageData<JobExecution> failed(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "100") int size) {
        return batchJobExecutionService.getFailedJobExecution(page, size);
    }

    @FunctionDefinition(functionName = "获取异常任务", functionCode = ModuleCodeStore.Function.VIEW)
    @GetMapping(value = "/unexcepted")
    public PageData<JobExecution> unexcepted(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "100") int size) {
        return batchJobExecutionService.getUnExceptedJobExecution(page, size);
    }

    @FunctionDefinition(functionName = "获取执行时间超过一定时间的任务", functionCode = ModuleCodeStore.Function.VIEW)
    @GetMapping(value = "/longtime")
    public PageData<JobExecution> longtime(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "100") int size, @RequestParam(name = "minute", defaultValue = "10") int minute) {
        return batchJobExecutionService.getLongTimeJobExecution(page, size, minute);
    }

}
